
<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/head.ftl">
    <script type="text/javascript" src="/js/My97DatePicker/WdatePicker.js"></script>

    <style>
        #ContentModal img{
            width: 100%;
        }
        #ContentModal .modal-body{
            overflow-x: auto;
            max-height: 500px;
        }
    </style>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#--设置当前要回显当前菜单,必须在载人菜单前完成设置-->
            <#assign menu = "news"/>
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">普通资讯</h1>
                </div>
            </div>
            <#--高级查询--->
            <form class="form-inline" id="searchForm" action="/news/list.do" method="post">
                <input type="hidden" id="currentPage" name="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入标题">
                </div>
                <button id="btn_query" class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>

                <#--<a role="button" class="btn btn-success inputBtn">-->
                    <#--<span class="glyphicon glyphicon-plus"></span> 添加-->
                <#--</a>-->
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>标题</th>
                    <th>封面</th>
                    <th>类型</th>
                    <th>发布时间</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>

                <#list pageInfo.list as t>
                <#--遍历查询得到的每一个domain对象-->
                    <tr>
                        <td>${t_index+1}</td>
                        <td>${(t.title)!}</td>
                        <td><img src="${t.coverUrl!}" width="40px"></td>
                        <td>${(t.typeDisplay)!}</td>
                        <td>${(t.releaseTime)?string("yyyy-MM-dd")!}</td>
                        <td>${(t.stateDisplay)!}</td>
                        <td>
                            <#--<a href ="javascript:;" class="btn btn-success changeStateBtn" data-state="1" data-id="${t.id}">推荐</a>-->
                            <a href ="javascript:;" class="btn btn-success showContentBtn" data-id="${t.id}">查看内容</a>
                            <button   class="btn btn-success updateBtn" data-json='${t.json}'>
                                推荐
                            </button>

                        </td>
                    </tr>
                </#list>

            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>
<#--查看文章-->
<div class="modal fade" id="ContentModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">资讯内容</h4>
            </div>
            <div class="modal-body">

            </div>
        </div>
    </div>
</div>

<#--新增或更新-->
<div id="newsCommendModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑/更新</h4>
            </div>
            <div class="modal-body">
                <form id="editForm" class="form-horizontal" method="post" action="/newsCommend/saveOrUpdate.do"
                      enctype="multipart/form-data" style="margin: -3px 118px">
                    <input id="newsCommendCoverUrl" type="hidden" name="coverUrl" />
                    <input  type="hidden" name="news.id"/>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">标题</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="title" name="title" placeholder="标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">摘要</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="summary" name="summary" placeholder="摘要">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面</label>
                        <div class="col-sm-6">
                            <img id="coverUrl" width="150px"/>
                            <a  role="button" class="btn btn-outline-light ibtn " id="coverBtn"></a>
                            <input type="file" id="multipartFile" name="multipartFile">
                        </div>
                    </div>
                    <#--<div class="form-group">-->
                        <#--<label class="col-sm-4 control-label">内容分类</label>-->
                        <#--<div class="col-sm-6">-->
                            <#--<select id="type" class="form-control"  name="type" >-->
                                <#--<option value="0">美食</option>-->
                                <#--<option value="1">法务</option>-->
                                <#--<option value="2">基础</option>-->
                            <#--</select>-->
                        <#--</div>-->
                    <#--</div>-->
                    <#--<div class="form-group">-->
                        <#--<label class="col-sm-4 control-label">作者</label>-->
                        <#--<div class="col-sm-6">-->
                            <#--<select  class="form-control"  name="user.id" >-->
                                <#--<#list  users as u>-->
                                    <#--<option value="${(u.id)!}">${(u.nickName)!}</option>-->
                                <#--</#list>-->
                            <#--</select>-->
                        <#--</div>-->
                    <#--</div>-->

                    <#--<textarea id="content" name="newsContent.content" class="ckeditor"  cols="10"  rows="10">-->

                    <#--</textarea>-->

                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-success" id="saveBtn" aria-hidden="true">保存</button>
                <button  class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
            </div>
        </div>
    </div>
</div>


<script>
    $(function () {
        // //富文本编辑框
        // var ck = CKEDITOR.replace( 'newsContent.content',{
        //     //图片预览服务器:存放之前传过图片
        //     filebrowserBrowseUrl: 'http://image.so.com',
        //     //图片上传请求路径
        //     filebrowserUploadUrl: '/uploadImage.do'
        // });

        $(".changeStateBtn").click(function () {
            var state = $(this).data("state");
            var id = $(this).data("id");
            $.get("/news/changeState.do",{state:state,id:id},function (data) {
                if(data.success){
                    window.location.reload();
                }else{
                    $.messager.alert("温馨提示",data.msg);
                }
            })
        })

        //查看资讯内容
        $(".showContentBtn").click(function () {
            var id = $(this).data("id");
            $.get("/news/getContent.do",{id:id},function(data){
                console.log(data);
                $("#ContentModal .modal-body").html(data.content);
                $("#ContentModal").modal("show");
            })

        })

//新增
        $(".inputBtn").click(function () {
            $("#editForm").clearForm(true);
            $("#coverUrl").attr("src","");
            $("#newsCommendModal").modal("show");

        });
//推荐 新增一个推荐类
        $(".updateBtn").click(function () {
            // 仅仅回显当前的标题和封面图片
            $("#editForm").clearForm(true);
            var json = $(this).data("json");
            console.log(json);
            if(json){
                $("#title").val(json.title);
                $("#coverUrl").attr("src",json.coverUrl);
                $("#newsCommendCoverUrl").val(json.coverUrl);
                $("#editForm input[name='news.id']").val(json.id);


            }
            $("#coverBtn").click(function () {
                $("#multipartFile").click();
            })

            $("#newsCommendModal").modal("show");
        })

        //点击保存
        $("#saveBtn").click(function () {


            $("#editForm").ajaxSubmit(function (data) {
                if (data.success) {
                    $.messager.confirm("温馨提示", "保存成功", function () {
                        window.location.reload();
                    })
                } else {
                    $.messager.alert("温馨提示", "保存失败");
                }

            });


        })

    })


</script>
</body>
</html>